install.packages('oaxaca')
library(oaxaca)

sc_data <- read.csv('social_capital_jpp.csv')

#### Table 3 models ####

model1 <- lm(sk2014 ~ new_exp_per_cap + educ2009 + income2009_10k + diversity2009 + inequality2009 + rural_pct + black_pop2009 + pct_foreign_born2009 + dem_pct, data = sc_data)

model1_place <- lm(sk2014 ~ new_exp_per_cap + educ2009 + income2009_10k + diversity2009 + inequality2009 + rural_pct + black_pop2009 + pct_foreign_born2009 + dem_pct + metropolitan + south, data = sc_data)

#### Table 4 models ####

metro_model <- lm(sk2014 ~ new_exp_per_cap + educ2009 + income2009_10k + diversity2009 + inequality2009 + rural_pct + black_pop2009 + pct_foreign_born2009 + dem_pct, data = subset(sc_data, sc_data$metropolitan == 1))

nonmetro_model <- lm(sk2014 ~ new_exp_per_cap + educ2009 + income2009_10k + diversity2009 + inequality2009 + rural_pct + black_pop2009 + pct_foreign_born2009 + dem_pct, data = subset(sc_data, sc_data$metropolitan == 0))

south_model <- lm(sk2014 ~ new_exp_per_cap + educ2009 + income2009_10k + diversity2009 + inequality2009 + rural_pct + black_pop2009 + pct_foreign_born2009 + dem_pct, data = subset(sc_data, sc_data$south == 1))

nonsouth_model <- lm(sk2014 ~ new_exp_per_cap + educ2009 + income2009_10k + diversity2009 + inequality2009 + rural_pct + black_pop2009 + pct_foreign_born2009 + dem_pct, data = subset(sc_data, sc_data$south == 0))

#### Table 5 models ####

metro_decomp_model <- oaxaca(sk2014 ~ new_exp_per_cap + educ2009 + income2009_10k + diversity2009 + inequality2009 + rural_pct + black_pop2009 + dem_pct + pct_foreign_born2009| metropolitan, data = sc_data)

south_decomp_model <- oaxaca(sk2014 ~ new_exp_per_cap + educ2009 + income2009_10k + diversity2009 + inequality2009 + rural_pct + black_pop2009 + dem_pct + pct_foreign_born2009| south, data = sc_data)





